package com.runa.rccprotocol.dto.lichuang;

import com.runa.protocol.dto.IResponseData;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.dto.ConcentratorRequestData;

/**
 * @author diandian
 * @Date 2022/5/7 13:40
 */
public class LiChuangEquRequestData extends ConcentratorRequestData {
    public LiChuangEquRequestData(String address) {
        super(address);
    }

    private byte[] requestData;

    @Override
    public byte[] getData() {
        return requestData;
    }

    @Override
    public boolean check(IResponseData data) {
        return true;
    }


    public void readHouseValve(String valveNo) {
        //FE FE FE FE 68 20 04 04 66 30 00 59 42 01 03 90 1F 00 74 16
        //FEH FEH　  68H　   51H　 Addr(7bytes）    01H　   03H　    90H 1FH  00H　      CS　    16H

        requestData = new byte[]{(byte) 0xFE, (byte) 0xFE,
                0x68,0x50,
                0,0,0,0,
                0x0,0x51,0x46,0x01,0x03, (byte) 0x90,0x1F,0x00,
                0,
                0x16};
        ByteUtil.tenstringToBcd(requestData, valveNo, 4, false);
        requestData[16] = ByteUtil.sum(requestData, 2, 14);
        setHaveResult(true);

//        requestData = newComm byte[]{(byte) 0xFE, (byte) 0xFE, (byte) 0xFE, (byte) 0xFE,
//                0x68,0x51,
//                0,0,0,0,
//                0x0,0x59,0x42,0x01,0x03, (byte) 0x90,0x1F,0x00,
//                0,
//                0x16};
//        ByteUtil.tenstringToBcd(requestData, valveNo, 6, false);
//        requestData[18] = ByteUtil.sum(requestData, 4, 15);
//        setHaveResult(true);
    }

    public void readHeatMeter(String meterNo) {
        //FE FE FE FE 68 20 04 04 66 30 00 59 42 01 03 90 1F 00 74 16
        requestData = new byte[]{(byte) 0xFE, (byte) 0xFE, (byte) 0xFE, (byte) 0xFE,
                0x68,0x20,
                0,0,0,0,
                0x0,0x59,0x42,0x01,0x03, (byte) 0x90,0x1F,0x00,
                0,
                0x16};
        ByteUtil.tenstringToBcd(requestData, meterNo, 6, false);
        requestData[18] = ByteUtil.sum(requestData, 4, 15);
        setHaveResult(true);
    }

    public static void main(String[] args) {
        String s = "30660404";
        LiChuangEquRequestData re = new LiChuangEquRequestData("");
        re.readHeatMeter(s);
        System.out.println(ByteUtil.byteToHexString(re.requestData));
    }

}